package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import com.hongxun.modules.bss.entity.DMaterialBuyEntity;
import com.hongxun.modules.bss.entity.PurchaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DDeviceBuyDao;
import com.hongxun.modules.bss.entity.DDeviceBuyEntity;
import com.hongxun.modules.bss.service.DDeviceBuyService;



@Service("dDeviceBuyService")
public class DDeviceBuyServiceImpl implements DDeviceBuyService {
	@Autowired
	private DDeviceBuyDao dDeviceBuyDao;

	@Override
	public DDeviceBuyEntity queryObject(String guid){
		return dDeviceBuyDao.queryObject(guid);
	}
	
	@Override
	public List<DDeviceBuyEntity> queryList(Map<String, Object> map){
		return dDeviceBuyDao.queryList(map);
	}
	@Override
	public List<DDeviceBuyEntity> queryListout(String pguid){
		return dDeviceBuyDao.queryListout(pguid);
	}

	@Override
	public List<DDeviceBuyEntity> queryListhz(String pguid) {
		return dDeviceBuyDao.queryListhz(pguid);
	}

	@Override
	public int queryTotal(Map<String, Object> map){
		return dDeviceBuyDao.queryTotal(map);
	}
	
	@Override
	public void save(DDeviceBuyEntity dDeviceBuy){
        if(dDeviceBuy.getGuid()==null||dDeviceBuy.getGuid().equals("")) {

		    dDeviceBuy.setGuid(UUID.randomUUID().toString());
        }
		dDeviceBuyDao.save(dDeviceBuy);
	}
	
	@Override
	public void update(DDeviceBuyEntity dDeviceBuy){
		dDeviceBuyDao.update(dDeviceBuy);
	}
	
	@Override
	public void delete(String guid){
		dDeviceBuyDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		dDeviceBuyDao.deleteBatch(guids);
	}
	@Override
	public List<DDeviceBuyEntity> queryListByDDguid(String[] guids){
		return 	dDeviceBuyDao.queryListByDDguid(guids);
	}
	@Override
	public void insertOrReplaceOrDelete(List<DDeviceBuyEntity> entities) {
		for (DDeviceBuyEntity d : entities) {
			if (d.getDBDatastate().equals("删除")) {
				dDeviceBuyDao.delete(d.getGuid());
			} else {
				DDeviceBuyEntity dDeviceBuyEntity = dDeviceBuyDao.queryObject(d.getGuid());
				if (dDeviceBuyEntity == null) {
					dDeviceBuyDao.save(d);
				} else {
					dDeviceBuyDao.update(d);
				}
			}
		}
	}

	@Override
	public List<PurchaseEntity> purchaseList(Map<String, Object> map) {
		return dDeviceBuyDao.purchaseList(map);
	}

	@Override
	public int queryTotalForPurchase(Map<String, Object> map) {
		return dDeviceBuyDao.queryTotalForPurchase(map);
	}
}
